package com.repair.dao.WeiXiuGangWei.impl;


import java.util.ArrayList;
import java.util.List;

import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;



import com.repair.dao.WeiXiuGangWei.IWeiXiuGangWeiDao;
import com.repair.domain.WeiXiuGangWei;
import com.repair.factory.HibernateSessionFactory;




public class WeiXiuGangWeiDao implements IWeiXiuGangWeiDao {

	@Override
	public void saveWeiXiuGangWei(WeiXiuGangWei obj) {
		Session session = HibernateSessionFactory.getSession();
		
		try{
			Transaction tx = session.beginTransaction();
			if(session != null){
				session.saveOrUpdate(obj);
			    tx.commit();
				session.flush();
				session.clear();
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		finally{
			if(session != null){
				session.flush();
				session.clear();
			}
		}
	}
	@Override
	@SuppressWarnings("unchecked")
	public List<WeiXiuGangWei> getAllWeiXiuGangWei(){
		List<WeiXiuGangWei> list = new ArrayList<WeiXiuGangWei>();
		Session session = HibernateSessionFactory.getSession();
		try{
			if(session != null){
				String sql = "select * from WEIXIUGANGWEI";
				SQLQuery query = session.createSQLQuery(sql);
				list = query.addEntity(WeiXiuGangWei.class).list();
			}
		}
		catch(Exception e){
			
		}
		return list;
	}
	@Override
	public void deleteWeiXiuGangWei(WeiXiuGangWei obj) {
		Session session = HibernateSessionFactory.getSession();
		try {
			Transaction tx = session.beginTransaction();
			if (session != null) {
				 session.delete(obj);
				tx.commit();
			}
		} catch (Exception e) {

		} finally {
			if (session != null) {
				session.flush();
				session.clear();
			}
		}

	}
}
